package com.oa.service;

import com.oa.dao.EmployeeDao;
import com.oa.pojo.Employee;
import com.oa.utils.MybatisUtils;

import java.util.List;

public class EmployeeService {
    public Employee selectById(Long employeeId) {
        return (Employee) MybatisUtils.executeQuery(sqlSession -> {
            EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
            return employeeDao.selectById(employeeId);
        });
    }

    public List<Employee> selectAll() {
        return (List<Employee>) MybatisUtils.executeQuery(sqlSession -> {
            EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
            return employeeDao.selectAll();
        });
    }

    public void insert(Employee employee) {
        MybatisUtils.executeUpdate(sqlSession -> {
            EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
            employeeDao.insert(employee);
            return null;
        });
    }

    public void deleteById(Long employeeId) {
        MybatisUtils.executeUpdate(sqlSession -> {
            EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
            employeeDao.delete(employeeId);
            return null;
        });
    }

    public void update(Employee employee) {
        MybatisUtils.executeUpdate(sqlSession -> {
            EmployeeDao employeeDao = sqlSession.getMapper(EmployeeDao.class);
            employeeDao.update(employee);
            return null;
        });
    }

}
